import java.util.ArrayList;
import java.util.List;

public class Node{
 

    public List<Node> children;
    public OnPrepos on;
    public ClearPrepos clear;
    public Action action;
    public float qValue;
    /**
     * Default ctor.
     */
    public Node() {
        super();
    }
 
    /**
     * Convenience ctor to create a Node<T> with an instance of T.
     * @param data an instance of T.
     */
    public Node(OnPrepos _on) {
       this.on = _on;
    }
    
    public Node(ClearPrepos _clear) {
        this.clear = _clear;
    }
    
    public Node(Action _action) {
    	this.action = _action;
    }
     
    public Node(float _qValue){
    	this.qValue = _qValue;
    }
    
    public Node checkPredicate(Node _node, ClearPrepos _param){
    	
    	Node child = null;
		List<Node> list= getChildren();
		
		if(!list.isEmpty()){
	    	if(_node.clear.equals(_param)){
	    		child = list.get(0);
	    	}    	
	    	else child = list.get(1);
		}
		
    	return child;
    }
    
    public Node checkPredicate(Node _node, OnPrepos _param){
    	
    	Node child = null;
		List<Node> list= getChildren();
		
		if(!list.isEmpty()){
	    	if(_node.on.equals(_param)){
	    		child = list.get(0);
	    	}    	
	    	else child = list.get(1);
		}
    	
    	return child;
    }
    public Node checkPredicate(Node _node, Action _param){
	
    	Node child = null;
		List<Node> list= getChildren();
		
		if(!list.isEmpty()){
	    	if(_node.action.equals(_param)){
	    		child = list.get(0);
	    	}    	
	    	else child = list.get(1);
		}
    	
    	return child;
    }
    
    
    
    /**
     * Return the children of Node<T>. The Tree<T> is represented by a single
     * root Node<T> whose children are represented by a List<Node<T>>. Each of
     * these Node<T> elements in the List can have children. The getChildren()
     * method will return the children of a Node<T>.
     * @return the children of Node<T>
     */
    public List<Node> getChildren() {
        if (this.children == null) {
            return new ArrayList<Node>();
        }
        return this.children;
    }
 

    /**
     * Sets the children of a Node<T> object. See docs for getChildren() for
     * more information.
     * @param children the List<Node<T>> to set.
     */
    public void setChildren(List<Node> children) {
        this.children = children;
    }
 
    /**
     * Returns the number of immediate children of this Node<T>.
     * @return the number of immediate children.
     */
    public int getNumberOfChildren() {
        if (children == null) {
            return 0;
        }
        return children.size();
    }
     
    /**
     * Adds a child to the list of children for this Node<T>. The addition of
     * the first child will create a new List<Node<T>>.
     * @param child a Node<T> object to set.
     */
    public void addChild(Node child) {
        if (children == null) {
            children = new ArrayList<Node>();
        }
        children.add(child);
    }
     
    /**
     * Inserts a Node<T> at the specified position in the child list. Will     * throw an ArrayIndexOutOfBoundsException if the index does not exist.
     * @param index the position to insert at.
     * @param child the Node<T> object to insert.
     * @throws IndexOutOfBoundsException if thrown.
     */
    public void insertChildAt(int index, Node child) throws IndexOutOfBoundsException {
        if (index == getNumberOfChildren()) {
            // this is really an append
            addChild(child);
            return;
        } else {
            children.get(index); //just to throw the exception, and stop here
            children.add(index, child);
        }
    }
     
    /**
     * Remove the Node<T> element at index index of the List<Node<T>>.
     * @param index the index of the element to delete.
     * @throws IndexOutOfBoundsException if thrown.
     */
    public void removeChildAt(int index) throws IndexOutOfBoundsException {
        children.remove(index);
    }
 
/*    public T getData() {
        return this.data;
    }
 
    public void setData(T data) {
        this.data = data;
    }*/
     
/*    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{").append(getData().toString()).append(",[");
        int i = 0;
        for (Node e : getChildren()) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(e.getData().toString());
            i++;
        }
        sb.append("]").append("}");
        return sb.toString();
    }*/
}
